package com.qys.livesMall.common.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * @packageName:
 * @className:LocalDateTimeToTimestampSerializer
 * @Description:
 * @author:guomx
 * @date:2023/6/309:58
 */
public class LocalDateTimeToTimestampSerializer extends JsonSerializer<LocalDateTime> {
    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        ZoneId zoneId = ZoneOffset.systemDefault();
        long timestamp = value.atZone(zoneId).toInstant().toEpochMilli();
        gen.writeNumber(timestamp);
    }
}

